'use strict';

const BaseService = require('../base');
const {
  CommonDeletedEnum
} = require("../../utils/enum");
const {
  listToTree
} = require("../../utils");
class SystemMenuService extends BaseService {
  static get modelName() {
    return 'System.SystemMenu';
  }
  async getSuperAdminMenuTree() {
    // 查找所有的权限菜单，组装成树结构，单独拆分组成树的方法
    const menuList = await this.model.findAll({
      where: {
        deleted: CommonDeletedEnum.NOT_DELETED
      },
      raw: true
    })
    return listToTree(menuList, {
      idKey: 'id',
      parentKey: 'parentId',
      childrenKey: 'children'
    }).sort((a, b) => a.sort - b.sort)
  }
}

module.exports = SystemMenuService;
